/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package General;

import java.io.*;
import java.util.Calendar;

/**
 *
 * @author Manuel
 */
public class Utilities {

    public static String buffer;

     public static synchronized void  writeToFile (String content, String fileName, boolean append){
        try {
            FileWriter fstream;
            if(append){
                 fstream = new FileWriter(fileName,true);
            }
            else{
                 fstream = new FileWriter(fileName);
            }
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(content);
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
     }


     public static String readFromFile(String fileName){
         String content ="";
         FileInputStream fis;
         DataInputStream dis;
         FileReader inputStream = null;
         FileWriter outputStream = null;

	 try{
            inputStream = new FileReader(fileName);
            int c;
            while ((c = inputStream.read()) != -1) {
                char nextChar = (char) c;
                content = content + nextChar;
            }
            inputStream.close();
        } catch(Exception e) {
            System.out.println("Could not read from file "+fileName+" !");
            System.out.println(e.getMessage());
        }

        return content;

     }

     public static void cleanMemory(){
                Runtime r = Runtime.getRuntime();
                r.gc();

     }

     public static String getCurrentTime(){
         Calendar cal = Calendar.getInstance();
         String currentDate = String.valueOf(cal.getTimeInMillis());
         return currentDate;
     }

}
